import Pages from '../../../pages/pages.vue'
import UserExcel from '../deal-user-excel/deal-user-excel.vue'
import Tab from '../tab/tab.vue'
import { showMsg, userCertificateList, setMenuType, sentCertificate } from '../../../../vuex/action'

export default {
  name: 'code-list',
  data() {
    return {
      pages: {
        start: 0,
        totalPages: 0,
        limit: 20
      },
      userList: [],
      phone: '',
      showCodeExcel: false
    }
  },
  components: {
    'vue-user-excel': UserExcel,
    'vue-pages': Pages,
    'vue-tab': Tab
  },
  vuex: {
    getters: {
      fresh: state => state.dataflowListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xUserCertificateList: userCertificateList,
      XSentCertificate: sentCertificate,
      xSetMenuType: setMenuType
    }
  },
  ready() {
    this.xSetMenuType('portfolio')
    this.getList({})
  },
  methods: {
    getList({phone=this.phone}) {
      this.xUserCertificateList({
        phone: phone
      })
        .then((data) => {
          this.userList = data.list
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    reSent(item) {
      this.XSentCertificate({
        phone: item.phone,
        recordId: item.id
      })
        .then((data) => {
          this.xShowMsg({
            type: 'info',
            content: '操作成功'
          })
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  },
  watch: {
    fresh() {
      if (this.fresh) {
        this.getList({})
      }
    }
  }
}
